//
//  CZQMsterPageVC.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/4/9.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQMsterPageVC.h"
#import "CZQCoachDetailModel.h"
#import "CZQCoachHeadTCell.h"
#import "CZQHomePageSectionHead.h"
#import "CZQHomeAbourTableViewCell.h"
#import "CZQHomeTimeTableViewCell.h"
#import "CZQHomeCourseTCell.h"
#import "CZQHomeVIPCommentCell.h"
#import "CZQShareViewController.h"
#import "CZQHomeAboutCoachVC.h"
#import "SMPagerTabView.h"
#import "SMPagerScrollView.h"
#import "CZQHomePageChileOneVC.h"
#import "CZQHomePageChildTwoVC.h"
#import "CZQHomePageChildTriVC.h"
#import "CZQCommentDetaiVC.h"
#import "CZQMasterPageView.h"
#import "CZQphotoShowTableViewCell.h"
#import "CZQCerTableViewCell.h"
#import "CZQVipDetalChildTableViewCell.h"
#import "CZQResumeModel.h"
#import "CZQEidtResumeViewController.h"
#import "CZQCoachMoveDetailVC.h"
#import "CZQCycleModel.h"
@interface CZQMsterPageVC ()
{
    //是否第一次进页面
   BOOL _isFirst;
    
    //动态数
    NSString *_total;
}
/**
 //数据源
 */
@property(nonatomic,strong)NSMutableArray *dataArr;

/**
 //数据源
 */
@property(nonatomic,strong)NSMutableArray *moveDataArr;


/**
 tableView
 */
@property(nonatomic,weak)UITableView *tableView;

@property(nonatomic,weak)CZQMasterPageView *headView;

/**
 教练简历数据
 */
@property(nonatomic,strong)CZQResumeModel *resumeModel;

/**
 教练详情模型数据
 */
@property(nonatomic,strong)CZQCoachDetailModel *model;
@end

@implementation CZQMsterPageVC

-(void)viewWillAppear:(BOOL)animated
{
    
    [super viewWillAppear:YES];
    
    
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];
    WS(weakSelf);
    
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //    [self loadData];
    
    //解决tablView向下偏移偏移
    
    if (@available(iOS 11.0, *)) {
        
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        
    } else {
        
        self.automaticallyAdjustsScrollViewInsets = NO;
        
    }
    
    _total = @"0";
    
    // 添加一个通知刷新数据
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(save) name:@"resume" object:nil];
    
    //获取本地数据
    if (!self.dict) {
        self.resumeModel = [CZQResumeModel resume];
    }else
    {
        self.resumeModel = [CZQResumeModel new];
    }
    
    
    self.title = @"我的主页";
    
    [self tableView];
    
    [self loadData];
    
    [self loadMoveData];
    
    [self getAttentList];
    
    [self getMasterAttentList];
    
    
}

-(void)dealloc
{
    //移除观察者 self
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 获取师傅关注列表判断自己是否关注
-(void)getMasterAttentList
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    NSString *userId = [[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"];
    
    [params setValue:userId  forKey:@"MemberID"];
    [params setValue:[[NSUserDefaults standardUserDefaults]objectForKey:@"MasterType" ]  forKey:@"UserType"];
    
    
    
    
    [HTTPTool GET:Get_Activity_ActivityFollowList parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@=%@",responseObject,userId);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSArray *resultArray = [responseObject objectForKey:@"rows"];
                  
                  if (resultArray.count == 0) {
                      return ;
                  }
                  
                  
                  self.headView.attendBtn.selected = NO;
                  
                  for (NSDictionary *dic in resultArray) {
                      
                      if ([dic[@"MemberID"] integerValue]  == [self.resumeModel.UserID integerValue]) {
                          
                          self.headView.attendBtn.selected = YES;
                          
                          
                          
                          return ;
                          
                      }
                      
                  }
                  
                  
                  
              }
              
          }
     
          failure:^(NSError *error){
              
              [self.tableView.mj_header endRefreshing];
              
              [MBProgressHUD hideHUDForView:self.view];
          }];
}


#pragma mark - 获取关注列表
-(void)getAttentList
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    NSString *userId = [[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"];
    
    
    [params setValue:self.resumeModel.UserID forKey:@"MemberID"];
    [params setValue :@"1" forKey:@"UserType"];
    
    
    [HTTPTool GET:Get_Activity_ActivityFollowList parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@=%@",responseObject,userId);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSArray *resultArray = [responseObject objectForKey:@"rows"];
                  
                  if (resultArray.count == 0) {
                      return ;
                  }
                  
                  self.headView.fanLable.text = [NSString stringWithFormat:@"粉丝:%ld",resultArray.count];
                  
                  
                      
              }
                  
                  
              
          }
     
          failure:^(NSError *error){
              
              [self.tableView.mj_header endRefreshing];
              
              [MBProgressHUD hideHUDForView:self.view];
          }];
}

-(void)loadData{
    
    
    
    
    
    
    
    [MBProgressHUD showMessage:@"加载中。。。" toView:self.view];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    NSString *userId;
    
    if (self.dict) {
        userId = self.dict[@"ID"];
        [params setObject:userId forKey:@"UserID"];
    }else
    {
        NSUserDefaults *userDetault = [NSUserDefaults standardUserDefaults];
        userId = [userDetault objectForKey:@"UserID"];
        [params setObject:userId forKey:@"UserID"];
    }
    
    //没有数据时添加id
    self.resumeModel.UserID = userId;
    
    
    NSString *url =[NSString stringWithFormat:@"%@/%@",Get_Resume,userId];
    
    [params setObject:@"1" forKey:@"page"];
    [params setObject:@"10" forKey:@"rows"];
    
    [HTTPTool GET:url parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@==%@",url,responseObject);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSArray *arr = [responseObject objectForKey:@"rows"] ;
                  
                  if (arr.count > 0) {
                      CZQResumeModel *resumeModel  = [CZQResumeModel mj_objectWithKeyValues:[arr firstObject]];
                      
                      self.resumeModel = resumeModel;
                      
                      if (self.dict) {
                          [self.headView.typeBtn setTitle:@"徒  弟"];
                          self.headView.prenticeLable.hidden = YES;
                      }else
                      {
                          [self.headView.typeBtn setTitle:@"师  傅"];
                      }
                      
                      self.headView.nickNameLabel.text = self.resumeModel.RealName;
                      
                      [self.headView.bgImageView sd_setImageWithURL:[NSURL URLWithString:[Helper imageUrlStringToChinese:self.resumeModel.Avatar imageType:mid_image]] placeholderImage:PlaceHold];
                      
                      [self.headView.sexBtn setImage:[self.resumeModel.Sex integerValue] == 0?@"icon_man":@"icon_women"];
                      
                      if (self.resumeModel.BirthDay) {
                          [self.headView.sexBtn setTitle:[NSString stringWithFormat:@"%ld",[Helper getAgeWithBirth:self.resumeModel.BirthDay]]];
                      }
                      self.headView.adressLable.text = [NSString stringWithFormat:@"%@丨%@丨ID%@",self.resumeModel.City,self.resumeModel.AddTime,self.resumeModel.UserID];
                      
                      [self.tableView reloadData];
                  }
                  
              }
              
          }
     
          failure:^(NSError *error){
              
              [self.tableView.mj_header endRefreshing];
              
              [MBProgressHUD hideHUDForView:self.view];
          }];
}

#pragma mark - 获取自己动态数

-(void)loadMoveData{
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    [params setObject:@"1" forKey:@"page"];
    
    [params setObject:@"10" forKey:@"rows"];
    
    [params setObject:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"]] forKey:@"VoteMemberID"];;
    
    if (self.dict) {
        
        [params setObject:self.dict[@"ID"] forKey:@"MemberID"];
        
        [params setObject:@"1" forKey:@"UserType"];
        
    }else
    {
        [params setObject:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"]] forKey:@"MemberID"];
        
        [params setObject:[NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"MasterType"]] forKey:@"UserType"];
    }
    
    
    
    [MBProgressHUD showMessage:@"请求中..." toView:self.view];
    
    [HTTPTool GET:GET_Activity_List parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@",responseObject);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSArray *resultArray = [responseObject objectForKey:@"rows"];
                  
                  
                  
                  _total = [[responseObject objectForKey:@"total"] stringValue];
                  
                  
                  
                  for (NSDictionary *resultDic in resultArray) {
                      
                      CZQCycleModel *cycle = [CZQCycleModel mj_objectWithKeyValues:resultDic];
                      
                      [self.moveDataArr addObject:cycle];
                      
                  }
                  
                  
                  
                  [MBProgressHUD hideHUDForView:self.view];
                  
                  [self.tableView reloadData];
              }
              
          }
     
          failure:^(NSError *error){
              
              [self.tableView.mj_header endRefreshing];
              
              [MBProgressHUD hideHUDForView:self.view];
          }];
}

#pragma mark -- 懒加载

-(CZQResumeModel *)resumeModel
{
    if (!_resumeModel) {
        _resumeModel = [[CZQResumeModel alloc]init];
    }
    return _resumeModel;
}

-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        
        _dataArr = [NSMutableArray array];
        
    }
    
    return _dataArr;
}

-(NSMutableArray *)moveDataArr
{
    if (!_moveDataArr) {
        
        _moveDataArr = [NSMutableArray array];
        
    }
    
    return _moveDataArr;
}

-(UITableView *)tableView
{
    if (!_tableView) {
        
        UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        
        tableView.delegate=self;
        
        tableView.dataSource=self;
        
        tableView.backgroundColor = BackGroundColor;
        
        tableView.estimatedRowHeight = 150;
        
        [self.view addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
            
        }];
        
//        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        //注册
        [tableView registerClass:[CZQHomeTimeTableViewCell class] forCellReuseIdentifier:@"CZQHomeTimeTableViewCell"];
        
        [tableView registerClass:[CZQHomeCourseTCell class] forCellReuseIdentifier:@"CZQHomeCourseTCell"];
        
        [tableView registerClass:[CZQHomeVIPCommentCell class] forCellReuseIdentifier:@"CZQHomeVIPCommentCell"];
        
        [tableView registerClass:[CZQMovePhotoShowTableViewCell class] forCellReuseIdentifier:@"CZQMovePhotoShowTableViewCell"];
        
        
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQCoachHeadTCell" bundle:nil]  forCellReuseIdentifier:@"cell"];
        
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQHomeAbourTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQHomeAbourTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQCerTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQCerTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQVipDetalChildTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQVipDetalChildTableViewCell"];
        

        CZQMasterPageView *tableHeadView = [[CZQMasterPageView alloc] init];
        
        [tableHeadView.attendBtn addTarget:self action:@selector(attend:)];
        
        [self.view addSubview:tableHeadView];
        [tableHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(tableView);
            
            make.left.width.mas_equalTo(self.view);
            
            make.height.mas_equalTo(self.view.height/3);
        }];
        
        [tableHeadView setNeedsLayout];
        [tableHeadView layoutIfNeeded];
        self.headView = tableHeadView;
        
        tableView.tableHeaderView = tableHeadView;
        
        _tableView = tableView;
    }
    return _tableView;
}

#pragma mark - UITableViewDataSource

//行数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 7;
}

//列数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2) {
        return 7;
    }else if (section == 5)
    {
       return self.resumeModel._CertificateExp.count;
    }
    else if (section == 6)
    {
        return  self.resumeModel._TrainingExp.count;
    }else
    {
        return 1;
    }
    return 0;
}

//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WS(weakSelf);
    
    if (indexPath.section == 0) {
        CZQHomeAbourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQHomeAbourTableViewCell"];
        
        cell.longLable.text = @"";
        
        cell.longTipLable.text = @"";
        
        cell.titleLable.text = isBlankString(self.resumeModel.Sign, @"暂无") ;
        
        return cell;
    }else if (indexPath.section == 1){
        
        //图片展示
        CZQMovePhotoShowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQMovePhotoShowTableViewCell"];
        
        cell.delegate = self;
        
        cell.section = 2;
        
        NSMutableArray *arrM = [NSMutableArray array];
        
        
        for (CZQCycleModel *cycle in self.moveDataArr) {
            
            
            
            if (cycle.Pics.length > 0) {
                
                [arrM addObjectsFromArray:[cycle.Pics componentsSeparatedByString:@","]];
                
            }
        }
        
        
        
        cell.arrM = arrM;
        
        
        return cell;
    }else if (indexPath.section == 2){
        CZQVipDetalChildTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQVipDetalChildTableViewCell"];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        NSArray *arr = @[@"姓名",@"身高",@"体重",@"职业",@"位置",@"常去地点",@"所属种类"];
        
        NSArray *titleArr = @[isBlankString(self.resumeModel.RealName, @""),isBlankString(self.resumeModel.Height, @""),isBlankString(self.resumeModel.Weight, @""),isBlankString(self.resumeModel.Professional, @""),isBlankString(self.resumeModel.City, @""),isBlankString(self.resumeModel.OftenPlace, @""),isBlankString(self.resumeModel.RealName, @"")];
        
//        cell.vipModel = [self.dataArr objectAtIndex:indexPath.row];
        
        [cell.nameBtn setTitle:arr[indexPath.row]];
        
        [cell.nameBtn setImage:@""];
        
        cell.titleLable.text = titleArr[indexPath.row];
        
        cell.fuTitleLable.hidden = YES;
        
        
        
        
        return cell  ;
        
    }else if (indexPath.section == 3){
        
        CZQHomeTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQHomeTimeTableViewCell"];
        
        
        if (self.resumeModel.FavTags.length > 0) {
            cell.arrM = [NSMutableArray arrayWithArray:[self.resumeModel.FavTags componentsSeparatedByString:@","]];
        }else
        {
            cell.arrM = nil;
        }
        
        
//        NSLog(@"%@",self.model.GetShopPlace);
        
        
        
        return cell;
        
        
    }else if (indexPath.section == 4){
        
        CZQHomeTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQHomeTimeTableViewCell"];
        
        if (self.resumeModel.StudySkill.length > 0) {
            cell.arrM = [NSMutableArray arrayWithArray:[self.resumeModel.StudySkill componentsSeparatedByString:@","]];
        }else
        {
            cell.arrM = nil;
        }
        
        return cell;
        
        
    }else if (indexPath.section == 5){
        
        //获得证书
        CZQCerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQCerTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        CZQCertificateExpModel *cerModel =[CZQCertificateExpModel mj_objectWithKeyValues:self.resumeModel._CertificateExp[indexPath.row]];
        
        [cell.cerImageView sd_setImageWithURL:[NSURL URLWithString:cerModel.Pic] placeholderImage:[UIImage imageNamed:@"icon_certificate"]];
        
        cell.cerNameLable.text = cerModel.Name;
        
        cell.cerAdreessLable.text = cerModel.Org;
        
        cell.cerTimeLable.text = cerModel.BeginDate;
        return cell;
        
    }else if (indexPath.section == 6){
        
        //经历
        CZQCerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQCerTableViewCell"];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        CZQTrainingExpModel *ctrainModel =[CZQTrainingExpModel mj_objectWithKeyValues:self.resumeModel._TrainingExp[indexPath.row]];
        
        [cell.cerImageView sd_setImageWithURL:[NSURL URLWithString:ctrainModel.Logo] placeholderImage:PlaceHold];
        
        cell.cerNameLable.text = ctrainModel.Content;
        
        cell.cerAdreessLable.text = ctrainModel.Org;
        
        cell.cerTimeLable.text = ctrainModel.BeginDate;
        
        return cell;
        
        
    }
    
    
    CZQCoachHeadTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    return cell  ;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    
    return 50;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    
    return 10;
}

//-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    if (indexPath.section == 4) {
//        return 500;
//    }return 150;
//
//}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    
//    if (section == 5) {
//        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [btn setTitle:@"更多"];
//        [btn setTitleColor:CSColorFromRGB(0x666666)];
//        btn.backgroundColor = CSWhiteColor;
//        btn.frame = CGRectMake(0, 0, kScreenWidth, 50);
//        
//        return btn;
//    }
//    UIView *view = [[UIView alloc]init];
//    
//    view.backgroundColor = BackGroundColor;
    
    return [[UIView alloc]initWithFrame:CGRectZero];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CZQHomePageSectionHead *sectionHead = [CZQHomePageSectionHead new];
    
    [sectionHead.moreBtn setImage:@"xiayibu"];
    
    sectionHead.titleLabe.font = MidBigFont;
    
    sectionHead.sepView.hidden = YES;
    
    [sectionHead.moreBtn imageOnTheTitleRightWithSpace:3];
    
    if (section == 0) {
        //关于他
        sectionHead.moreBtn.hidden = YES;
        sectionHead.titleLabe.text = @"个人介绍";
        sectionHead.howLabe.text = @"";
        [sectionHead.moreBtn addTarget:self action:@selector(about)];
    }
    else if (section == 1)
    {
        
        //TA的动态
        sectionHead.titleLabe.text = @"TA的动态";
        sectionHead.howLabe.text = [NSString stringWithFormat:@"(%@)",_total];
        [sectionHead.moreBtn addTarget:self action:@selector(move)];
        
    }
    else if (section == 2)
    {
        //TA的信息
        sectionHead.titleLabe.text = @"TA的信息";
        [sectionHead.moreBtn setImage:@""];
        sectionHead.howLabe.text = @"";
        [sectionHead.moreBtn setTitle:@"关于他60%"];
        [sectionHead.moreBtn setTitleColor: [UIColor redColor]];
        
    }
    else if (section == 3)
    {
        //擅长
        sectionHead.titleLabe.text = @"擅长";
        sectionHead.howLabe.text = @"";
        sectionHead.moreBtn.hidden = YES;
        
    }
    else if (section == 4)
    {
        //想学
        sectionHead.titleLabe.text = @"想学";
        sectionHead.howLabe.text = @"";
        sectionHead.moreBtn.hidden = YES;
        
    }
    else if (section == 5)
    {
        //获奖
        sectionHead.titleLabe.text = @"TA的获奖";
        sectionHead.howLabe.text = [NSString stringWithFormat:@"(%ld)",self.resumeModel._CertificateExp.count];
        
        [sectionHead.moreBtn addTarget:self action:@selector(cer)];
        
    }
    else if (section == 6)
    {
        //经历
        sectionHead.titleLabe.text = @"TA的经历";
        sectionHead.howLabe.text = [NSString stringWithFormat:@"(%ld)",self.resumeModel._TrainingExp.count];
        [sectionHead.moreBtn addTarget:self action:@selector(org)];
        
    }
    
    return sectionHead;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当离开某行时，让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

#pragma mark - 关注
-(void)attend:(UIButton *)sender
{
    
    
    NSString *url;
    
    NSString *tip;
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    if (sender.selected == NO) {
        //关注
        url = Post_Activity_FollowOperate;
        
        tip = @"关注成功";
        
    }else
    {
        //取消关注
        url = Post_Activity_DelFollow;
        
        tip = @"取消关注成功";
        
    }
    
    [params setObject:[[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"] forKey:@"MemberID"];
    
    [params setObject:[[NSUserDefaults standardUserDefaults] valueForKey:@"MasterType"] forKey:@"UserType"];
    
    if (self.dict) {
        [params setObject:self.dict[@"ID"] forKey:@"ToMemberID"];
        [params setObject:@"2" forKey:@"ToUserType"];
    }else
    {
        [params setObject:[[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"] forKey:@"ToMemberID"];
        [params setObject:[[NSUserDefaults standardUserDefaults] valueForKey:@"MasterType"] forKey:@"ToUserType"];
        
    }
    
    
    [MBProgressHUD showMessage:@"请求中..." toView:self.view];
    
    
    
    [HTTPTool POSTRaw:url parameters:params
     
              success:^(id responseObject){
                  
                  [MBProgressHUD hideHUDForView:self.view];
                  
                  
                  if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                      
                      sender.selected = !sender.selected;
                      
                      [MBProgressHUD showText:tip];
                      
                      [MBProgressHUD hideHUDForView:self.view];
                  }
                  
              }
     
              failure:^(NSError *error){
                  
                  [MBProgressHUD hideHUDForView:self.view];
              }];
}

#pragma mark - 动态
-(void)move
{
    CZQCoachMoveDetailVC *move = [CZQCoachMoveDetailVC new];
    
    CZQCycleModel *model = [CZQCycleModel new];
    
    
    
    model.MemberID = self.resumeModel.UserID;
    
    model.UserType = @"1";
    
    move.cycleModel = model;
    
    
    [self.navigationController pushViewController:move animated:YES];
    
}
#pragma mark - 获得奖项
-(void)cer
{
    CZQEidtResumeViewController*eidt = [CZQEidtResumeViewController new];
    
    eidt.section = 5;
    
    eidt.resumeModel = self.resumeModel;
    
    eidt.title = @"证书列表";
    
    [self.navigationController pushViewController:eidt animated:YES];
    
}
#pragma mark - 经历
-(void)org
{
    
    CZQEidtResumeViewController*eidt = [CZQEidtResumeViewController new];
    
    eidt.section = 6;
    
    eidt.resumeModel = self.resumeModel;
    
    eidt.title = @"学习培训";
    
    [self.navigationController pushViewController:eidt animated:YES];
}

#pragma mark - 更新简历数据

-(void)save
{
    [self loadData];
    
    [self loadMoveData];
    
    [self getAttentList];
    
    [MBProgressHUD showMessage:@"请求中..." toView:self.view];
    
    
    
    
    NSDictionary *params = [self.resumeModel toDictionary];
    
    NSLog(@"%@",params);
    
    
    
    [HTTPTool POSTRaw:Post_Resume_Operate parameters:params
     
              success:^(id responseObject){
                  
                  [MBProgressHUD hideHUDForView:self.view];
                  
                  if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                      
                      [MBProgressHUD showText:@"保存成功"];
                      
                      self.resumeModel.ID = [responseObject objectForKey:@"ResumeID"];
                      
                      //归档教练数据
                      [CZQResumeModel saveResume:self.resumeModel];
                      
                      [self.tableView reloadData];
                  }
                  
              }
     
              failure:^(NSError *error){
                  
                  [MBProgressHUD hideHUDForView:self.view];
              }];
    
}

#pragma Logo图片选择
-(void)logoSelect:(UIButton *)photoSelect{
    
    ZLPhotoPickerViewController *pickerVc = [[ZLPhotoPickerViewController alloc] init];
    
    if (photoSelect.tag == 0) {
        
    }
    
    pickerVc.maxCount = 9;
    
    // Jump AssetsVc
    //    pickerVc.status = PickerViewShowStatusSavePhotos;
    // Recoder Select Assets
    //    pickerVc.selectPickers = self.assets;
    // Filter: PickerPhotoStatusAllVideoAndPhotos, PickerPhotoStatusVideos, PickerPhotoStatusPhotos.
    
    pickerVc.photoStatus = PickerPhotoStatusPhotos;
    // Desc Show Photos, And Suppor Camera
    pickerVc.isShowCamera = YES;
    pickerVc.topShowPhotoPicker = YES;
    
    // CallBack
    __weak typeof(self)weakSelf = self;
    
    pickerVc.callBack = ^(NSArray<ZLPhotoAssets *> *status){
        
        for (ZLPhotoAssets *assets in status) {
            
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:assets];
            
            photo.asset = assets;
            
            
            UIImage *image = nil;
            
            //拍照
            if ([photo.asset isKindOfClass:[UIImage class]]) {
                
                image = (UIImage *)photo.asset;
            }
            else{
                image = [assets thumbImage];
                
            }
            
            
            
            [weakSelf uploadImage:image];
        }
        
        
        
        
        //            break;
        
        
    };
    
    [pickerVc showPickerVc:self];
}

#pragma mark - 刷新

-(void)CZQphotoShowTableViewCellRefreashData
{
    
    [self save];
    
}
#pragma mark 上传头像
-(void)uploadImage:(UIImage *)image{
    
    
    
    NSData *imageData;
    
    
    
    
    imageData  = UIImageJPEGRepresentation(image,0.1);
    
    [MBProgressHUD showMessage:@"上传中.." toView:self.view];
    
    RAYUploader *upload = [RAYUploader defaultUploader];
    
    [upload uploadWithData:imageData complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        
        [MBProgressHUD hideHUDForView:self.view];
        
        if (key) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                NSString *picUrl = [NSString stringWithFormat:@"%@%@",QiNiuBase,key];
                
//                [self.photoShowdataArrM addObject:  picUrl];
//                
//                self.resumeModel.Pics = [self.photoShowdataArrM componentsJoinedByString:@","];
                
                NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:2];
                
                [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
            });
            
        }
        
    }];
    
}
#pragma mark - 分享
-(void)share
{
    CZQShareViewController *share = [CZQShareViewController new];
    
    [self.navigationController pushViewController:share animated:YES];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
